<?php
require 'inc/classifier.php';
?>

<html>
    <head>
        <title>WINO classifier</title>
          <style>
            body {
                font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
            }
            h1 a {
                text-decoration: none;
                color: #3b5998;
            }
            h1 a:hover {
                text-decoration: underline;
            }
        </style>
    </head>
    <body>
        <h1>Learner and classifier - WINO</h1>
        <form action="model.php"  method="POST">
            Insert C parameter for the classifier: <input type="text" name="c" value="0.01" /><br/>
            Scegli la cartella di test:
<?php
                $subf = get_subfolders(dirname(__FILE__)."/inc/data");
                foreach ($subf as $sub)
                    print '          <input type="radio" name="folder" value="'.$sub.'"/>'."$sub\n";
?>
            <br/>
        <input type="submit" name="generate" value="Generate"/>
        <input type="submit" name="start" value="Start" />

        </form>
<?php
            if (isset($_POST['generate'])) {
                $fold = $_POST['folder'];
                $labels = csv_to_labels("inc/data/$fold/test/test_labels.txt");
                $output = csv_to_examples($labels,"inc/data/$fold/test/test.csv",",",array(1));
                write_to_file($output, "inc/data/$fold/test/test.dat");
                $labels = csv_to_labels("inc/data/$fold/train/train_labels.txt");
                $output = csv_to_examples($labels,"inc/data/$fold/train/train.csv",",",array(1));
                write_to_file($output, "inc/data/$fold/train/train.dat");
            } else if (isset ($_POST['start'])){
                $fold = $_POST['folder'];
                $errors;
?>
            <p>Learn:</p>
            <textarea cols=""  rows="8" style="width:100%">
<?php
                learn("inc/data/$fold/train/train.dat", "inc/data/$fold/train/model", true, $_POST['c']);
?>
            </textarea>
            <p>Classification:</p>
            <textarea cols=""  rows="8" style="width:100%">
<?php
                classifier("inc/data/$fold/test/test.dat", "inc/data/$fold/train/model", $errors, true);
?>
            </textarea>
<?php


            //print csv_to_examples(array(1, 2, 3, 4, 5), "a.csv");
            //print_r (classify("model", "test.dat", $errors, true));
            //print "</br><b>Errors</b>: $errors";
            //        $output = array();
            //
            //        print "<b>Retval</b>: " . $retval . "\n";
            //        foreach ($output as $out) {
            //            print($out . "<br>");
            //        }

            }
?>
</html>